const app = require("../app");
const {
  NAME_IS_ALREADY_EXISTS,
  NAME_OR_PASSWORD_IS_REQUIRED,
  NAME_IS_NOT_EXISTS,
  NAME_IS_NOT_INCORRENT,
  UNAUTHORIZATION,
  OPERATION_IS_NOT_ALLOWED,
} = require("../config/error");


app.on("error", (error, ctx) => {
  let code = 0;
  let msg = "";

  switch (error) {
    case NAME_OR_PASSWORD_IS_REQUIRED:
      code = -1001;
      msg = "账号密码不能为空";
      break;
    case NAME_IS_ALREADY_EXISTS:
      code = -1002;
      msg = "账号已经存在";
      break;
    case NAME_IS_NOT_EXISTS:
      code = -1003;
      msg = "登陆用户不存在";
      break;
    case NAME_IS_NOT_INCORRENT:
      code = -1004;
      msg = "密码不正确";
      break;
    case UNAUTHORIZATION:
      code = -1005;
      msg = "未授权";
      break;
    case OPERATION_IS_NOT_ALLOWED:
      code = -1006;
      msg = "操作没有权限";
      break;
  }

  ctx.body = { code, msg };
});
